package org.lc.cmd.connect.impl.ws;

import lombok.Getter;
import org.lc.cmd.SentSysReq;
import org.lc.cmd.connect.CmdServerConfig;
import org.lc.cmd.connect.impl.BaseServerSession;
import org.lc.cmd.model.WsData;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;
import java.text.AttributedString;
import java.util.concurrent.Future;

public class WsSession extends org.lc.cmd.impl.ws.WebSocketSession implements BaseServerSession {

    @Getter
    private final String id;

    private final WebSocketSession webSocketSession;

    @Getter
    private final WsServer server;

    public WsSession(String id, WebSocketSession webSocketSession, WsServer server) {
        super(CmdServerConfig.defaultProvider);
        this.id = id;
        this.webSocketSession = webSocketSession;
        this.server = server;
    }

    @Override
    public boolean isOpen() {
        return webSocketSession.isOpen();
    }

    @Override
    protected void sendData(WsData data) {

    }

    @Override
    public <T> Future<T> sendSysReq(SentSysReq<T> req) {
        return null;
    }

    @Override
    public void notify(AttributedString string) {

    }

    @Override
    public void close() throws IOException {
        server.removeSession(getId());
        webSocketSession.close();
    }
}
